home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / dpp / proto.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  14KB  |  541 lines

  1.  
  2.  
  3. /*  Copyright (c) 1993-1996 Algorithms Corporation  */
  4. /*  All rights reserved.  */
  5.  
  6.  
  7.  
  8.  
  9. /*  This file automatically generated by dpp - do not edit  */
  10.  
  11. #define    DPP_STRATEGY    2
  12. #define    DPP_FASTWIDE    0
  13.  
  14.  
  15.  
  16. #line 16 "proto.d"
  17. #include <ctype.h> 
  18. #include <string.h> 
  19.  
  20. #include "dpp.h" 
  21.  
  22. #define    CLASS    Prototype_c
  23. #define    ivType    Prototype_iv_t
  24.  
  25. #include "generics.h"
  26.  
  27. object    Prototype_c;
  28.  
  29.  
  30. #line 31 "proto.c"
  31. typedef struct  _Prototype_iv_t  {
  32.     object iName;
  33.     object iFixedName;
  34.     object iRtn;
  35.     object iArgs;
  36.     object iProto;
  37.     object iParams;
  38.     int iVararg;
  39.     int iException;
  40.     int iNeedRest;
  41.     object iLastArg;
  42. }    Prototype_iv_t;
  43.  
  44.  
  45. #line 36 "proto.d"
  46. #define strne(a, b) strcmp(a, b) 
  47. #define streq(a, b) !strcmp(a, b) 
  48.  
  49. #define istart(x) (isalpha(x) || (x) == '_') 
  50. #define irest(x) (isalnum(x) || (x) == '_') 
  51.  
  52.  
  53. extern char *trunc_mname(char *mname); 
  54.  
  55.  
  56. cmeth objrtn Prototype_cm_gNew(object self)
  57.     return gShouldNotImplement(self, "gNew"); 
  58.  
  59. cmeth objrtn Prototype_cm_gNewWithStrStr(object self, char *nm, char *rt)
  60.     object obj = oSuper(Prototype_c, gNew, self)(self); 
  61.     ivType *iv = ivPtr(obj); 
  62.     iv->iName = gNewWithStr(String, nm); 
  63.     iv->iRtn = gNewWithStr(String, rt); 
  64.     return obj; 
  65.  
  66. imeth objrtn Prototype_im_gDispose(object self)
  67. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  68.     gDispose(iv->iName); 
  69.     if (iv->iFixedName) 
  70.         gDispose(iv->iFixedName); 
  71.     gDispose(iv->iRtn); 
  72.     if (iv->iArgs) 
  73.         gDeepDispose(iv->iArgs); 
  74.     if (iv->iProto) 
  75.         gDeepDispose(iv->iProto); 
  76.     if (iv->iParams) 
  77.         gDeepDispose(iv->iParams); 
  78.     if (iv->iLastArg) 
  79.         gDeepDispose(iv->iLastArg); 
  80.     return oSuper(Prototype_c, gDispose, self)(self); 
  81.  
  82. imeth int Prototype_im_gHash(object self)
  83. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  84.     return gHash(iv->iName); 
  85.  
  86. imeth int Prototype_im_gCompare(object self, object obj)
  87. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  88.     ChkArgTyp(obj, 2, CLASS); 
  89.     return gCompare(iv->iName, ivPtr(obj)->iName); 
  90.  
  91. static void remove_variable(char *buf, char *var) 
  92.     register int i, vi = -1; 
  93.  
  94.     for (i=0 ; buf[i] ; ) 
  95.         if (istart(buf[i])) { 
  96.         vi = i++; 
  97.         while (buf[i] && irest(buf[i])) 
  98.             i++; 
  99.     } else 
  100.         i++; 
  101.  
  102.     if (vi >= 0) { 
  103.         for (i=vi ; irest(buf[i]) ; ) 
  104.             *var++ = buf[i++]; 
  105.         if (vi && buf[vi-1] == ' ') 
  106.             vi--; 
  107.         for (i=vi+1 ; buf[i] && irest(buf[i]) ; i++); 
  108.         memmove(buf+vi, buf+i, strlen(buf+i) + 1); 
  109.     } 
  110.     *var = '\0'; 
  111.  
  112. static void make_proto(ivType *iv, object ar) 
  113.     object seq, nxt, prv=NULL; 
  114.     char buf[100], var[50]; 
  115.  
  116.     iv->iProto = gNew(LinkObject); 
  117.     iv->iParams = gNew(LinkObject); 
  118.     for (seq=gSequence(ar) ; nxt = gNext(seq) ; ) { 
  119.         strcpy(buf, gStringValue(nxt)); 
  120.         remove_variable(buf, var); 
  121.         gAddLast(iv->iProto, gNewWithStr(String, buf)); 
  122.         if (!*var) { 
  123.             iv->iNeedRest = 1; 
  124.             if (iv->iLastArg) 
  125.                 DISPOSE(iv->iLastArg); 
  126.             iv->iLastArg = prv ? gCopy(prv) : prv; 
  127.         } 
  128.         gAddLast(iv->iParams, prv=gNewWithStr(String, *var ? var : "_rest_")); 
  129.     } 
  130.  
  131. imeth objrtn Prototype_im_gPrintArgs(object self, object fobj)
  132. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  133.     object seq, nxt; 
  134.     int n=0; 
  135.  
  136.     if (iv->iArgs && !iv->iVararg && !iv->iException) 
  137.         for (seq=gSequence(iv->iArgs) ; nxt = gNext(seq) ; ) { 
  138.         if (n++) 
  139.             gPuts(fobj, ", "); 
  140.         gPuts(fobj, (char *) nxt); 
  141.     } 
  142.     else 
  143.         gPuts(fobj, "object self, ..."); 
  144.     return self; 
  145.  
  146. imeth objrtn Prototype_im_gPrintFixedArgs(object self, object fobj)
  147. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  148.     object seq, nxt; 
  149.     int n=0; 
  150.  
  151.     if (iv->iArgs) 
  152.         for (seq=gSequence(iv->iArgs) ; nxt = gNext(seq) ; ) { 
  153.         if (n++) 
  154.             gPuts(fobj, ", "); 
  155.         gPuts(fobj, (char *) nxt); 
  156.     } 
  157.     else 
  158.         gPuts(fobj, "object self, ..."); 
  159.     return self; 
  160.  
  161. imeth objrtn Prototype_im_gPrintMethArgs(object self, object fobj, int Strategy, int vararg)
  162. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  163.     object seq, nxt; 
  164.     int n=0; 
  165.  
  166.     if (vararg && Strategy != 1) { 
  167.         gPut(fobj, gNewToken(Token, "object self", 0L, 0)); 
  168.         gPut(fobj, gNewToken(Token, ",", 0L, 1)); 
  169.         gPut(fobj, gNewToken(Token, "va_list _rest_", 0L, 0)); 
  170.     } else if (iv->iArgs) 
  171.         for (seq=gSequence(iv->iArgs) ; nxt = gNext(seq) ; ) { 
  172.         if (n++) 
  173.             gPut(fobj, gNewToken(Token, ",", 0L, 1)); 
  174.         if (Strategy > 1 && streq(gStringValue(nxt), "...")) 
  175.             gPut(fobj, gNewToken(Token, "va_list _rest_", 0L, 0)); 
  176.         else 
  177.             gPut(fobj, gNewToken(Token, gStringValue(nxt), 0L, 0)); 
  178.     } 
  179.     gPut(fobj, gNewToken(Token, ")", 0L, 0)); 
  180.     return self; 
  181.  
  182. imeth objrtn Prototype_im_gPrintVars(object self, object fobj)
  183. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  184.     object seq, nxt; 
  185.     int n=0; 
  186.     char *v; 
  187.  
  188.     if (iv->iParams && !iv->iVararg && !iv->iException) 
  189.         for (seq=gSequence(iv->iParams) ; nxt = gNext(seq) ; ) { 
  190.         if (n++) 
  191.             gPuts(fobj, ", "); 
  192.         v = gStringValue(nxt); 
  193.         if (*v) 
  194.             gPuts(fobj, (char *) nxt); 
  195.         else 
  196.             gPuts(fobj, "_rest_"); 
  197.     } 
  198.     else 
  199.         gPuts(fobj, "self, _rest_"); 
  200.     return self; 
  201.  
  202. imeth objrtn Prototype_im_gUseVars(object self, object fobj)
  203. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  204.     object seq, nxt; 
  205.     char *v; 
  206.     int n = 0; 
  207.  
  208.     if (!iv->iParams) 
  209.         return self; 
  210.     for (seq=gSequence(iv->iParams) ; nxt = gNext(seq) ; ) 
  211.         if (n++) { 
  212.         v = gStringValue(nxt); 
  213.         if (*v && strne(v, "_rest_")) 
  214.             vPrintf(fobj, "\tUSE(%s);\n", v); 
  215.     } 
  216.     return self; 
  217.  
  218. #if 0 
  219.  
  220. static void print_args(ivType *iv, object ar) 
  221.     object seq, nxt; 
  222.     int n=0; 
  223.  
  224.     vPrintf(stdoutStream, "%s %s(", gStringValue(iv->iRtn), gStringValue(iv->iName)); 
  225.     for (seq=gSequence(ar) ; nxt = gNext(seq) ; ) { 
  226.         if (n++) 
  227.             gPuts(stdoutStream, ", "); 
  228.         gPuts(stdoutStream, (char *) nxt); 
  229.     } 
  230.     gPuts(stdoutStream, ")\n"); 
  231.     if (iv->iVararg) 
  232.         gPuts(stdoutStream, "Varargs is set\n"); 
  233.     else 
  234.         gPuts(stdoutStream, "Varargs is not set\n"); 
  235.     if (iv->iException) 
  236.         gPuts(stdoutStream, "Exception is set\n"); 
  237.     else 
  238.         gPuts(stdoutStream, "Exception is not set\n"); 
  239.  
  240. #endif 
  241.  
  242. imeth objrtn Prototype_im_gSetArgs(object self, object ar)
  243. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  244.     if (iv->iArgs) 
  245.         DEEPDISPOSE(iv->iArgs); 
  246.     if (iv->iProto) 
  247.         iv->iProto = DEEPDISPOSE(iv->iProto); 
  248.     if (iv->iParams) 
  249.         iv->iParams = DEEPDISPOSE(iv->iParams); 
  250.     if (iv->iArgs = ar) 
  251.         make_proto(iv, ar); 
  252.     if (ar && gSize(ar) == 2 && streq(gStringValue(gLast(ar)), "...")) 
  253.         iv->iVararg = 1; 
  254. #if 0 
  255.         print_args(iv, iv->iArgs); 
  256.     print_args(iv, iv->iProto); 
  257. #endif 
  258.         return self; 
  259.  
  260. imeth objrtn Prototype_im_gReturnType(object self)
  261. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  262.     return iv->iRtn; 
  263.  
  264. imeth objrtn Prototype_im_gArgs(object self)
  265. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  266.     return iv->iArgs; 
  267.  
  268. imeth objrtn Prototype_im_gPrototype(object self)
  269. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  270.     return iv->iProto; 
  271.  
  272. imeth objrtn Prototype_im_gParameters(object self)
  273. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  274.     return iv->iParams; 
  275.  
  276. imeth objrtn Prototype_im_gDeepCopy(object self)
  277. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  278.     object nobj; 
  279.     ivType *niv; 
  280.  
  281.     nobj = oSuper(Prototype_c, gDeepCopy, self)(self); 
  282.     niv = ivPtr(nobj); 
  283.     niv->iName = gDeepCopy(iv->iName); 
  284.     niv->iFixedName = iv->iFixedName ? gDeepCopy(iv->iFixedName) : iv->iFixedName; 
  285.     niv->iRtn = gDeepCopy(iv->iRtn); 
  286.     if (iv->iArgs) { 
  287.         niv->iArgs = gDeepCopy(iv->iArgs); 
  288.         niv->iProto = gDeepCopy(iv->iProto); 
  289.         niv->iParams = gDeepCopy(iv->iParams); 
  290.     } 
  291.     if (iv->iLastArg) 
  292.         niv->iLastArg = gDeepCopy(iv->iLastArg); 
  293.     return nobj; 
  294.  
  295. imeth int Prototype_im_gMatchNoError(object self, object mproto)
  296. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  297.     ivType *miv = ivPtr(mproto); 
  298.     object mseq, gseq, garg, marg; 
  299.  
  300. #if 0 
  301.         print_args(iv, iv->iArgs); 
  302.     print_args(miv, miv->iArgs); 
  303. #endif 
  304.  
  305.         if (gCompare(miv->iRtn, iv->iRtn)) 
  306.         return 0; 
  307.  
  308.     if ((!miv->iArgs || miv->iVararg || miv->iException) && (!iv->iArgs || iv->iVararg)) 
  309.         return 1; 
  310.  
  311.     if (miv->iException || !miv->iArgs || miv->iVararg || !iv->iArgs || iv->iVararg) 
  312.         return 0; 
  313.  
  314.     if (gSize(miv->iArgs) != gSize(iv->iArgs)) 
  315.         return 0; 
  316.  
  317.     mseq = gSequence(miv->iArgs); 
  318.     gseq = gSequence(iv->iArgs); 
  319.     garg = (object) 1; 
  320.     while (marg = gNext(mseq)) { 
  321.         garg = gNext(gseq); 
  322.         if (!garg || gCompare(marg, garg)) { 
  323.             DISPOSE(mseq); 
  324.             if (garg) 
  325.                 DISPOSE(gseq); 
  326.             return 0; 
  327.         } 
  328.     } 
  329.     if (garg) 
  330.         DISPOSE(gseq); 
  331.  
  332.     return 1; 
  333.  
  334. imeth int Prototype_im_gMatch(object self, object mproto)
  335. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  336.     ivType *miv = ivPtr(mproto); 
  337.     object mseq, gseq, garg, marg; 
  338.     int n, error=0; 
  339.  
  340. #if 0 
  341.         print_args(iv, iv->iArgs); 
  342.     print_args(miv, miv->iArgs); 
  343. #endif 
  344.  
  345.         if (gCompare(miv->iRtn, iv->iRtn)) { 
  346.         error = 1; 
  347.         vPrintf(stdoutStream, "Method %s and generic %s have different return types\n", 
  348.             trunc_mname(gStringValue(miv->iName)), 
  349.             gStringValue(iv->iName)); 
  350.     } 
  351.  
  352.     if (iv->iException || miv->iVararg && iv->iVararg) 
  353.         return error; 
  354.  
  355.     if (miv->iVararg || iv->iVararg) { 
  356.         vPrintf(stdoutStream, "Method %s and generic %s have different arguments\n", 
  357.             trunc_mname(gStringValue(miv->iName)), 
  358.             gStringValue(iv->iName)); 
  359.         return 1; 
  360.     } 
  361.  
  362.     if (!miv->iProto) { 
  363.         vPrintf(stdoutStream, "Warning: Method %s has no prototype.\n", 
  364.             trunc_mname(gStringValue(miv->iName))); 
  365.         return error; 
  366.     } 
  367.  
  368.     if (!iv->iProto) 
  369.         return error; 
  370.  
  371.     if (gSize(miv->iProto) != gSize(iv->iProto)) { 
  372.         vPrintf(stdoutStream, "Method %s and generic %s have a different number of arguments\n", 
  373.             trunc_mname(gStringValue(miv->iName)), 
  374.             gStringValue(iv->iName)); 
  375.         return 1; 
  376.     } 
  377.  
  378.     mseq = gSequence(miv->iProto); 
  379.     gseq = gSequence(iv->iProto); 
  380.     garg = (object) 1; 
  381.     for (n=1 ; marg = gNext(mseq) ; ++n) { 
  382.         garg = gNext(gseq); 
  383.         if (!garg) { 
  384.             error = 1; 
  385.             vPrintf(stdoutStream, "Method %s and generic %s have a different number of arguments.\n", 
  386.                 trunc_mname(gStringValue(miv->iName)), 
  387.                 gStringValue(iv->iName)); 
  388.             break; 
  389.         } 
  390. #line 409 "proto.d"
  391.         if (gCompare(marg, garg)) { 
  392.             error = 1; 
  393.             vPrintf(stdoutStream, "Method %s and generic %s have different argument types (%d)\n", 
  394.                 trunc_mname(gStringValue(miv->iName)), 
  395.                 gStringValue(iv->iName), n); 
  396.         } 
  397.     } 
  398.     if (marg) 
  399.         DISPOSE(mseq); 
  400.     if (garg) 
  401.         DISPOSE(gseq); 
  402.  
  403.     return error; 
  404.  
  405. imeth objrtn Prototype_im_gGetMGName(object self)
  406. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  407.     return iv->iName; 
  408.  
  409. imeth objrtn Prototype_im_gChangeName(object self, char *nm)
  410. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  411.     if (iv->iName) 
  412.         gChangeStrValue(iv->iName, nm); 
  413.     else 
  414.         iv->iName = gNewWithStr(String, nm); 
  415.     return self; 
  416.  
  417. imeth objrtn Prototype_im_gGetFixedName(object self)
  418. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  419.     return iv->iFixedName; 
  420.  
  421. imeth objrtn Prototype_im_gChangeFixedName(object self, char *nm)
  422. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  423.     if (iv->iFixedName) 
  424.         gChangeStrValue(iv->iFixedName, nm); 
  425.     else 
  426.         iv->iFixedName = gNewWithStr(String, nm); 
  427.     return self; 
  428.  
  429. imeth objrtn Prototype_im_gVarArg(object self)
  430. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  431.     iv->iVararg = 1; 
  432.     return self; 
  433.  
  434. imeth int Prototype_im_gIsVarArg(object self)
  435. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  436.     return iv->iNeedRest || iv->iVararg; 
  437.  
  438. imeth char * Prototype_im_gLastArg(object self)
  439. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  440.     return iv->iLastArg && !iv->iVararg ? gStringValue(iv->iLastArg) : "self"; 
  441.  
  442. imeth objrtn Prototype_im_gException(object self)
  443. { Prototype_iv_t *iv = GetIVs(Prototype, self);
  444.     iv->iException = 1; 
  445.     return self; 
  446.  
  447.  
  448. #line 483 "proto.c"
  449.  
  450. objrtn    Prototype_initialize(void)
  451. {
  452.     static  CRITICALSECTION  cs;
  453.     static  int volatile once = 0;
  454.  
  455.     ENTERCRITICALSECTION(_CI_CS_);
  456.     if (!once) {
  457.         INITIALIZECRITICALSECTION(cs);
  458.         once = 1;
  459.     }
  460.     LEAVECRITICALSECTION(_CI_CS_);
  461.  
  462.     ENTERCRITICALSECTION(cs);
  463.  
  464.     if (Prototype_c) {
  465.         LEAVECRITICALSECTION(cs);
  466.         return Prototype_c;
  467.     }
  468.     INHIBIT_THREADER;
  469.     Prototype_c = gNewClass(Class, "Prototype", sizeof(Prototype_iv_t), 0, END);
  470.     cMethodFor(Prototype, gNew, Prototype_cm_gNew);
  471.     cMethodFor(Prototype, gNewWithStrStr, Prototype_cm_gNewWithStrStr);
  472.     iMethodFor(Prototype, gMatch, Prototype_im_gMatch);
  473.     iMethodFor(Prototype, gChangeFixedName, Prototype_im_gChangeFixedName);
  474.     iMethodFor(Prototype, gLastArg, Prototype_im_gLastArg);
  475.     iMethodFor(Prototype, gChangeName, Prototype_im_gChangeName);
  476.     iMethodFor(Prototype, gArgs, Prototype_im_gArgs);
  477.     iMethodFor(Prototype, gMatchNoError, Prototype_im_gMatchNoError);
  478.     iMethodFor(Prototype, gPrintMethArgs, Prototype_im_gPrintMethArgs);
  479.     iMethodFor(Prototype, gGetFixedName, Prototype_im_gGetFixedName);
  480.     iMethodFor(Prototype, gGetMGName, Prototype_im_gGetMGName);
  481.     iMethodFor(Prototype, gCompare, Prototype_im_gCompare);
  482.     iMethodFor(Prototype, gPrototype, Prototype_im_gPrototype);
  483.     iMethodFor(Prototype, gPrintVars, Prototype_im_gPrintVars);
  484.     iMethodFor(Prototype, gSetArgs, Prototype_im_gSetArgs);
  485.     iMethodFor(Prototype, gDispose, Prototype_im_gDispose);
  486.     iMethodFor(Prototype, gPrintArgs, Prototype_im_gPrintArgs);
  487.     iMethodFor(Prototype, gParameters, Prototype_im_gParameters);
  488.     iMethodFor(Prototype, gPrintFixedArgs, Prototype_im_gPrintFixedArgs);
  489.     iMethodFor(Prototype, gReturnType, Prototype_im_gReturnType);
  490.     iMethodFor(Prototype, gIsVarArg, Prototype_im_gIsVarArg);
  491.     iMethodFor(Prototype, gHash, Prototype_im_gHash);
  492.     iMethodFor(Prototype, gUseVars, Prototype_im_gUseVars);
  493.     iMethodFor(Prototype, gDeepDispose, Prototype_im_gDispose);
  494.     iMethodFor(Prototype, gVarArg, Prototype_im_gVarArg);
  495.     iMethodFor(Prototype, gException, Prototype_im_gException);
  496.     iMethodFor(Prototype, gDeepCopy, Prototype_im_gDeepCopy);
  497.  
  498.     ENABLE_THREADER;
  499.  
  500.     LEAVECRITICALSECTION(cs);
  501.  
  502.     return Prototype_c;
  503. }
  504.  
  505.  
  506.  
  507.